package com.bt7274.enums;

public enum PromotionType {
    NORMAL("normal"),
    FREE("free"),
    HALF_PRICE("50%"),
    DOUBLE_UPLOAD("2X"),
    DOUBLE_DOWNLOAD("0.5X"),
    DOUBLE_UPLOAD_DOWNLOAD("2X&0.5X");

    private final String description;

    PromotionType(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据传入的字符串获取对应的促销类型
     * @param promotionStr 传入的促销类型字符串
     * @return 对应的促销类型，若未匹配则返回普通
     */
    public static PromotionType getPromotionTypeByString(String promotionStr) {
        if (promotionStr == null) {
            return NORMAL;
        }
        for (PromotionType type : PromotionType.values()) {
            if (type.name().equalsIgnoreCase(promotionStr) || type.description.equalsIgnoreCase(promotionStr)) {
                return type;
            }
        }
        return NORMAL;
    }
}